package top100.array;

import utils.Utils;

import java.util.Arrays;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/21 9:10
 * @description:
 */
public class Solution189 {
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);

    }

    public void reverse(int[] nums, int left, int right) {
        while (left < right) {
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }
    }

    public static void main(String[] args) {
        Solution189 solution = new Solution189();
        int[] nums = {1, 2, 3, 4, 5, 6, 7};
        solution.rotate(nums, 3);
        System.out.println(Arrays.toString(nums));
        int[] nums2 = {-1};
        solution.rotate(nums2, 2);
        System.out.println(Arrays.toString(nums2));
    }

}
